package com.liush.srb.core.controller.admin;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liush.srb.base.result.ResponseVo;
import com.liush.srb.core.pojo.entity.UserLoginRecord;
import com.liush.srb.core.service.UserLoginRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: liush
 * @CreateTime: 2023-04-03  18:45
 * @Description: 用户登录日志模块
 */

@RestController
//@CrossOrigin
@Api(tags = "用户登录日志模块")
@RequestMapping("/admin/core/userLoginRecord")
public class AdminUserLoginRecordController {

    @Resource
    UserLoginRecordService userLoginRecordService;

    @ApiOperation("查询会员最近10条登录日志")
    @GetMapping("user/{userId}")
    public ResponseVo list(@PathVariable("userId") Long userId) {
        List<UserLoginRecord> userLoginRecordList = userLoginRecordService.list(Wrappers.lambdaQuery(UserLoginRecord.class)
                .eq(UserLoginRecord::getUserId, userId)
                .orderByDesc(UserLoginRecord::getCreateTime)
                .last("limit 10"));
        return ResponseVo.ok().data("items", userLoginRecordList);
    }
}
